package com.ice.work.moment.tencent.controller;

import com.honeybee.cloud.framework.common.idwork.IdWorker;
import com.honeybee.cloud.framework.common.response.ResponseEntity;
import com.ice.work.moment.tencent.facade.controller.IWxUserController;
import com.ice.work.moment.tencent.facade.dto.UserDTO;
import com.ice.work.moment.tencent.facade.mapper.UserConvertMapper;
import com.ice.work.moment.tencent.facade.model.User;
import com.ice.work.moment.tencent.facade.request.AddUserRequest;
import com.ice.work.moment.tencent.facade.vo.UserVO;
import com.ice.work.moment.tencent.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description user
 * @Author DELL
 * @Create 2019-05-17
 * @Since 1.0.0
 */
@RestController
@SuppressWarnings("unused")
public class WxUserController implements IWxUserController {

    @Autowired
    private IdWorker idWorker;
    @Autowired
    private IUserService userService;

    @Override
    public ResponseEntity<Void> addUser(AddUserRequest request) {
        User user = UserConvertMapper.INSTANCE.toUser(request);
        user.setId(idWorker.nextId());
        Boolean success = userService.addUser(user);
        if (success) {
            return ResponseEntity.ok();
        }
        return ResponseEntity.error();
    }

    @Override
    public ResponseEntity<UserVO> findUserByOpenId(String openId) {
        UserDTO user = userService.findUserByOpenId(openId);
        UserVO userVO = UserConvertMapper.INSTANCE.toVO(user);
        return ResponseEntity.ok(userVO);
    }
}
